// Package middleware 图形验证码模块
package middleware

import (
	"github.com/mayoushang/gocaptcha"
)

// Captcha 生成验证码
func Captcha(length int, dx int, dy int, ttf string) (captcha []byte, code string) {
	gocaptcha.SetFontFamily(ttf)
	captchaImage, _ := gocaptcha.NewCaptchaImage(dx, dy, gocaptcha.RandLightColor())
	captchaImage.DrawNoise(gocaptcha.CaptchaComplexLower)
	captchaImage.DrawTextNoise(gocaptcha.CaptchaComplexLower)
	code = gocaptcha.RandText(length)
	captchaImage.DrawText(code)
	captchaImage.DrawBorder(gocaptcha.ColorToRGB(0x17A7A7A))
	//captchaImage.DrawSineLine()
	return captchaImage.ImageBytes(gocaptcha.ImageFormatPng), code
}
